package resources.dao;

import resources.pojo.pe_cmpany;

public class CompanyDAO extends DatabaseDAO {
	public static boolean update(String action,pe_cmpany c){
		String sql = "call sp_pe_company_info(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			conn.setAutoCommit(false);
			cs = conn.prepareCall(sql);
			cs.setString(1, action);
			cs.setString(2, c.getCmpanyne());
			cs.setString(3, c.getNatnnlity());
			cs.setString(4, c.getBk());
			cs.setString(5, c.getBkat());
			cs.setString(6, c.getAdrs());
			cs.setString(7, c.getPenmbr());
			cs.setString(8, c.getFxnmbr());
			cs.setString(9, c.getEl());
			cs.setString(10, c.getWbse());
			cs.setString(11, c.getCnttprsn());
			cs.setString(12, c.getTxce());
			cs.setString(13, c.getBusinslice());
			cs.setString(14, c.getDscptn());
			cs.executeUpdate();
			conn.commit();
		} catch (Exception e) {
			try {
				conn.rollback();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			e.printStackTrace();
			return false;
		}	
		return true;
	}
	
	public static pe_cmpany getCompanyInfo(){
		pe_cmpany temp = new  pe_cmpany();
		String sql = "select * from pe_cmpany";
		try {
			conn.setAutoCommit(false);
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while(rs.next()){
				temp.setId(rs.getString("id"));
				temp.setCmpanyne(rs.getString("cmpanyne"));
				temp.setNatnnlity(rs.getString("natnnlity"));
				temp.setBk(rs.getString("bk"));
				temp.setBkat(rs.getString("bkat"));
				temp.setAdrs(rs.getString("adrs"));
				temp.setPenmbr(rs.getString("penmbr"));
				temp.setFxnmbr(rs.getString("fxnmbr"));
				temp.setEl(rs.getString("el"));
				temp.setWbse(rs.getString("wbse"));
				temp.setCnttprsn(rs.getString("cnttprsn"));
				temp.setTxce(rs.getString("txce"));
				temp.setBusinslice(rs.getString("businslice"));
				temp.setDscptn(rs.getString("dscptn"));
				temp.setLg(rs.getString("lg"));
			}
			conn.commit();
		} catch (Exception e) {
			try {
				conn.rollback();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			e.printStackTrace();
		}
		return temp;
	}
}
